
import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/storeEvaluate/provider/provider.dart';
import 'package:boss/ui/page/storeEvaluate/widget/comment_list.dart';
import 'package:boss/ui/page/storeEvaluate/widget/item_header.dart';
import 'package:boss/ui/widget/calendar/calendar.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:boss/ui/widget/search_bar.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ContentPage extends StatefulWidget {
  String unionOrderId;

  ContentPage({Key key, this.unionOrderId}) : super(key: key);

  @override
  _State createState() => _State();
}

class _State extends State<ContentPage> with WidgetsBindingObserver {
  GlobalKey<CommentListState> childKey = GlobalKey();

  TextEditingController inputController = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState

    super.initState();
    WidgetsBinding.instance.addObserver(this);
    if (widget.unionOrderId != null && widget.unionOrderId != '') {
      inputController.text = widget.unionOrderId;
    }
  }

  @override
  void didChangeMetrics() {
    super.didChangeMetrics();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      setState(() {
        var provider = Provider.of<StoreCommentProvider>(
          context,
          listen: false,
        );
        provider.keyboardHeight = num.parse(MediaQuery.of(context).viewInsets.bottom.toString());
        provider.notifyListeners();
      });
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    WidgetsBinding.instance.removeObserver(this);
    inputController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Padding(
        padding: EdgeInsets.only(),
        child: Column(
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(
                left: 24.w,
                right: 24.w,
              ),
              child: Column(
                children: <Widget>[
                  (widget.unionOrderId != null && widget.unionOrderId != '')
                      ? Container()
                      : Padding(
                        padding:EdgeInsets.only(

                          top:6.w,
                          bottom:3.w,
                        ),
                        child: Row(
                    children: <Widget>[
                        Expanded(
                          child: Container(
                            child: SearchBar(
                              controller: inputController,
                              hintText: '请输入要查询的订单号',
                              onChanged: (e) {
                                var provider = Provider.of<StoreCommentProvider>(
                                  context,
                                  listen: false,
                                );
                                provider.searchText = e;
                              },
                            ),
                          ),
                        ),

//                        Padding(
//                          padding:EdgeInsets.only(
//                            left:6.w,
//                            right:0.w,
//                          ),
//                          child: Image.asset(
//                            'assets/image/close_icon.png',
//                            width: 30.w,
//                            height: 30.w,
//                            fit: BoxFit.cover,
//                          ),
//                        ),
                        Padding(
                          padding: EdgeInsets.only(
                            left: 12.w,
                            right: 12.w,
                          ),
                          child: Container(
                            width: 120.w,
                            height:80.w,
                            child: Padding(
                              padding:EdgeInsets.symmetric(
                                vertical:12.w,
                              ),
                              child: RaisedButton(
                                elevation: 0,
                                //按钮下面的阴影
                                highlightElevation: 0,
                                child: Text(
                                  "查询",
                                  style: TextStyleConstant().white_26,
                                ),
                                color: ColorConstant.ff5770f6,
                                textColor: Colors.white,
                                onPressed: () {
                                  childKey.currentState.implementUpdateData();
                                },
                                disabledColor: Colors.grey,
                                disabledTextColor: Colors.white,
                                disabledElevation: 4,
                                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.0)), //圆角大小
                              ),
                            ),
                          ),
                        ),
                        GestureDetector(
                          onTap: () async {
                            var provider = Provider.of<StoreCommentProvider>(
                              context,
                              listen: false,
                            );
                            var res = await showCalendar(
                              GlobalPageContext.instance.context,
                              startDateTime: DateTime.parse(provider.beginTime),
                              endDateTime: DateTime.parse(provider.endTime),
//                              maxDateTime:DateTime.now(),
                              minDateTime: DateTime(2000),
                            );
                            if (res != null) {
                              provider.beginTime = res[0].toString().substring(0, 10);
                              provider.endTime = res[1].toString().substring(0, 10);

                              childKey.currentState.implementUpdateData();
                            }
                          },
                          child: BaseImage(
                            'assets/image/MyStoreEvaluateIcon.png',
                            width: 52.w,
                            height: 52.w,
                          ),
                        ),
                    ],
                  ),
                      ),
                  Consumer<StoreCommentProvider>(builder: (context, provider, _) {
                    return Column(
                      children: <Widget>[
                        Text(
                          "${provider.beginTime.substring(0, 10)} 至 ${provider.endTime.substring(0, 10)}",
                          style: TextStyleConstant().normal_2_32,
                        ),
                        Padding(
                          padding: EdgeInsets.only(
                            top: 10.w,
                            bottom: 6.w,
                          ),
                          child: ItemHeader(
                            provider: provider,
                          ),
                        ),
                      ],
                    );
                  }),
                ],
              ),
            ),
            Expanded(
              child: CommentList(
                key: childKey,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
